//
//  FQRegisterViewController.m
//  WeChat
//
//  Created by 方桥 on 16/5/14.
//  Copyright © 2016年 方桥. All rights reserved.
//

#import "FQRegisterViewController.h"
#import "MBProgressHUD+HM.h"
@interface FQRegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;

@end

@implementation FQRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)registerBtnClicked:(id)sender {
    
    //注册
    // 保存注册的用户名和密码
    [FQAccount shareAccount].registerUser = self.userField.text;
    [FQAccount shareAccount].registerPwd = self.pwdField.text;
    
    [MBProgressHUD showMessage:@"正在注册中"];
    // 调用注册的方法
    [FQXmppTool sharedFQXmppTool].registerOperation = YES;
    __weak typeof (self) selfVc = self;
    [[FQXmppTool sharedFQXmppTool] xmppRegister:^(XMPPResultType resultType) {
        [selfVc handleXMPPResult:resultType];
    }];
}

-(void)handleXMPPResult:(XMPPResultType)resultType
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUD];
        if (resultType == XMPPResultTypeRegisterSucess) {
            [MBProgressHUD showSuccess:@"恭喜注册成功"];
        }else{
            [MBProgressHUD showError:@"用户名重复"];
        }
    });
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
